home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / graphicgems4.lha / GemsIV / graph_layout / window.hxx < prev   
Encoding:
Text File  |  1995-02-06  |  3.4 KB  |  123 lines

  1. /******************************************************************************
  2. **    TEST FILE FOR graph (Dynamic Layout Alg)
  3. **
  4. **    HEADER - C++ X-WINDOW class library based on Xlib
  5. **
  6. ** Author: dr. Szirmay-Kalos Laszlo (szirmay@fsz.bme.hu)
  7. **       Technical University of Budapest, Hungary
  8. *****************************************************************************/
  9.  
  10. #include <X11/Xlib.h>
  11. #include <X11/Xutil.h>
  12. #include <X11/Xos.h>
  13. #include <stdio.h>
  14. #include <math.h>
  15. #include <stdlib.h>
  16. #include <string.h>
  17.  
  18. //******************************************************************
  19. //    CONSTANTS
  20. //******************************************************************
  21. #define WINDOW_WIDTH    400
  22. #define WINDOW_HEIGHT    400
  23. #define FALSE        0
  24. #define TRUE        1
  25.  
  26. //******************************************************************
  27. //    TYPES
  28. //******************************************************************
  29. typedef short  CoOrd;
  30. typedef char * pchar;
  31. typedef char   BOOL;
  32.  
  33. //===================================================================
  34. class App {
  35. //===================================================================
  36. public:
  37.     void        Start( int argc, char * argv[] );
  38.     void        Error( char * mess, int line = -1 );
  39.     void        Warning( char * mess );
  40.     void        Quit( void );
  41. };
  42.  
  43. extern App app;
  44.  
  45. //===================================================================
  46. class Point {
  47. //===================================================================
  48. private:
  49.     CoOrd x;
  50.     CoOrd y;
  51. public:
  52.             Point( )            { x = y = 0;        }
  53.             Point(CoOrd x0, CoOrd y0)    { x = x0; y = y0;   }
  54.     CoOrd&  X()                    { return x;        }
  55.     CoOrd&  Y()                    { return y;        }
  56. };
  57.  
  58. //===================================================================
  59. class RectAngle {
  60. //===================================================================
  61. private:
  62.     CoOrd hor_pos;
  63.     CoOrd ver_pos;
  64.     CoOrd width;
  65.     CoOrd height;
  66.  
  67. public:
  68.         RectAngle(CoOrd hp, CoOrd vp, CoOrd w, CoOrd h)
  69.           { hor_pos = hp; ver_pos = vp; width = w; height = h;    }
  70.     CoOrd&  HorPos()    { return hor_pos;        }
  71.     CoOrd&  VerPos()    { return ver_pos;        }
  72.     CoOrd&  Width()    { return width;            }
  73.     CoOrd&  Height()    { return height;        }
  74. };
  75.  
  76. //===================================================================
  77. class KeyEvent {
  78. //===================================================================
  79.     KeySym        key_sym;
  80.     XComposeStatus    status;
  81.     char        ascii;
  82. public:
  83.         KeyEvent( XKeyEvent * xe )
  84.         { XLookupString( xe, &ascii, 1, &key_sym, &status ); }
  85.     int        GetASCII( void ) { return ascii; }
  86. };
  87.  
  88. //===================================================================
  89. class ExposeEvent {
  90. //===================================================================
  91.     RectAngle  area;
  92. public:
  93.            ExposeEvent( XExposeEvent * xe )
  94.           :area(xe->x, xe->y, xe->width, xe->height) { }
  95.     RectAngle& GetExposedArea( )    { return area;    }
  96. };
  97.  
  98. //===================================================================
  99. class AppWindow {
  100. //===================================================================
  101.     GC        gc, gc_inv;
  102.     Window        win;
  103.     Display *    dpy;
  104.     int        screen;
  105.     RectAngle    canvas;
  106.     Point        beam;
  107. protected:
  108.     virtual void    KeyPressed( KeyEvent * ) {}
  109.     virtual void    ExposeAll( ExposeEvent * ) {}
  110.  
  111.     RectAngle    Canvas( void );
  112.     void        RePaint( void );
  113.     void        Text( char * text, Point position );
  114.     void        MoveTo( Point to );
  115.     void        LineTo( Point to );
  116.     void        DrawRectangle( RectAngle& rect );
  117.  
  118. public:
  119.             AppWindow( int argc, char * argv[] );
  120.     void        MessageLoop( );
  121. };
  122.  
  123.